<!DOCTYPE html>
<html lang="en-us">
  
  <head>
  <meta charset="UTF-8">
  <title>tbox</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="theme-color" content="#157878">
  <meta name="description" content="A glib-like cross-platform C library">
  <meta name="keywords" content="network,asio,coroutine,xml,json,plist,container,iterator,algorithm,stream,cross-platform,embed,ios,android,linux,c" /> 

  <link rel="stylesheet" href="/assets/css/normalize.css">
  <link rel='stylesheet' href="/assets/css/opensans.css" type='text/css'>
  <link rel="stylesheet" href="/assets/css/cayman.css">

  <!-- baidu stats -->
  <!--
    <script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?eb3c91c672a001d78a113bfb8e42017a";
      var s = document.getElementsByTagName("script")[0]; 
      s.parentNode.insertBefore(hm, s);
    })();
    </script>
    -->
</head>


  <body>
    <section class="page-header">
  <h1 class="project-name">tbox</h1>
  <h2 class="project-tagline">A glib-like cross-platform C library</h2>
  <a href="/#/home" class="btn">GET STARTED</a>
  <br><br>
  <iframe src="https://ghbtns.com/github-btn.html?user=tboox&repo=tbox&type=star&count=true" frameborder="0" scrolling="0" width="110px" height="20px"></iframe>
    <span class="donate" style="width: 100px">
      <img src="/assets/img/patreon.png">
      <a href="/pages/donation.html#donate">Support us</a>
    </span>
  <br><br>
  <ul id="translations">
      <li><a href="/cn/" class="nav-link">中文</a></li>
      <li class="delimiter">|</li>
      <li><a href="/" class="nav-link">English</a></li>
    </ul>
</section>



    <section class="main-content">
      
      <h1 id="the-treasure-box-library">The Treasure Box Library</h1>

<h2 id="introduction">Introduction</h2>

<p>TBOX is a glib-like cross-platform C library that is simple to use yet powerful in nature.</p>

<p>The project focuses on making C development easier and provides many modules (.e.g stream, asio, regex, container, algorithm …), 
so that any developer can quickly pick it up and enjoy the productivity boost when developing in C language.</p>

<p>It supports the following platforms:</p>

<ul>
  <li>Windows</li>
  <li>Macosx</li>
  <li>Linux</li>
  <li>Android</li>
  <li>iOS</li>
</ul>

<p>And it provides many compiling options using <a href="http://www.xmake.io">xmake</a>:</p>

<ul>
  <li>Release: Disable debug information, assertion, memory checking and enable optimization.</li>
  <li>Debug: Enable debug information, assertion, memory checking and disable optimization.</li>
  <li>Small: Disable all extensional modules and enable space optimization.</li>
  <li>Micro: compiling micro library (~64K) for the embed system.</li>
</ul>

<p>If you want to know more, please refer to:</p>

<ul>
  <li><a href="https://github.com/waruqi/tbox/wiki/documents">Documents</a></li>
  <li><a href="https://github.com/waruqi/tbox">Github</a></li>
  <li><a href="http://tboox.org">HomePage</a></li>
</ul>

<h2 id="features">Features</h2>

<h4 id="the-stream-library">The stream library</h4>

<ul>
  <li>Supports file, data, http and socket source</li>
  <li>Supports the stream filter for gzip, charset and…</li>
  <li>Implements stream transfer</li>
  <li>Implements the static buffer stream for parsing data</li>
  <li>Supports coroutine and implements asynchronous operation</li>
</ul>

<h4 id="the-coroutine-library">The coroutine library</h4>

<ul>
  <li>Provides high-performance coroutine switch(refer to <a href="http://tboox.org/2016/10/28/benchbox-coroutine/">reports</a>)</li>
  <li>Supports arm, arm64, x86, x86_64 ..</li>
  <li>Provides channel interfaces</li>
  <li>Provides semaphore and lock interfaces</li>
  <li>Supports io socket and stream operation in coroutine</li>
  <li>Provides some io servers (http ..) using coroutine</li>
  <li>Provides stackfull and stackless coroutines</li>
</ul>

<h4 id="the-database-library">The database library</h4>

<ul>
  <li>Supports mysql and sqlite3 database and enumerates data using the iterator mode</li>
</ul>

<h4 id="the-xml-parser-library">The xml parser library</h4>

<ul>
  <li>Supports DOM and SAX mode and Supports xpath</li>
</ul>

<h4 id="the-serialization-and-deserialization-library">The serialization and deserialization library</h4>

<ul>
  <li>Supports xml, json, bplist, xplist, binary formats</li>
</ul>

<h4 id="the-memory-library">The memory library</h4>

<ul>
  <li>Implements some memory pools for optimizing memory</li>
  <li>Supports fast memory error detecting. it can detect the following types of bugs for the debug mode:
    <ul>
      <li>out-of-bounds accesses to heap and globals</li>
      <li>use-after-free</li>
      <li>double-free, invalid free</li>
      <li>memory leaks</li>
    </ul>
  </li>
</ul>

<h4 id="the-container-library">The container library</h4>

<ul>
  <li>Implements hash table, single list, double list, vector, stack, queue
and min/max heap. Supports iterator mode for algorithm</li>
</ul>

<h4 id="the-algorithm-library">The algorithm library</h4>

<ul>
  <li>Uses the iterator mode</li>
  <li>Implements find, binary find and reverse find algorithm</li>
  <li>Implements sort, bubble sort, quick sort, heap sort and insert sort algorithm</li>
  <li>Implements count, walk items, reverse walk items, for_all and rfor_all</li>
</ul>

<h4 id="the-network-library">The network library</h4>

<ul>
  <li>Implements dns(cached)</li>
  <li>Implements ssl(openssl, polarssl, mbedtls)</li>
  <li>Implements http</li>
  <li>Implements cookies</li>
  <li>Supports ipv4, ipv6</li>
  <li>Supports coroutine</li>
</ul>

<h4 id="the-platform-library">The platform library</h4>

<ul>
  <li>Implements timer, fast and low precision timer</li>
  <li>Implements atomic and atomic64 operation</li>
  <li>Implements spinlock, mutex, event, semaphore, thread and thread pool</li>
  <li>Implements file, socket operation</li>
  <li>Implements poller using epoll, poll, select, kqueue …</li>
  <li>Implements switch context interfaces for coroutine</li>
</ul>

<h4 id="the-charset-library">The charset library</h4>

<ul>
  <li>Supports utf8, utf16, gbk, gb2312, uc2 and uc4</li>
  <li>Supports big endian and little endian mode</li>
</ul>

<h4 id="the-zip-library">The zip library</h4>

<ul>
  <li>Supports gzip, zlibraw, zlib formats using the zlib library if exists</li>
  <li>Implements lzsw, lz77 and rlc algorithm</li>
</ul>

<h4 id="the-utils-library">The utils library</h4>

<ul>
  <li>Implements base32, base64 encoder and decoder</li>
  <li>Implements assert and trace output for the debug mode</li>
  <li>Implements bits operation for parsing u8, u16, u32, u64 data</li>
</ul>

<h4 id="the-math-library">The math library</h4>

<ul>
  <li>Implements random generator</li>
  <li>Implements fast fixed-point calculation, Supports 6-bits, 16-bits, 30-bits fixed-point number</li>
</ul>

<h4 id="the-libc-library">The libc library</h4>

<ul>
  <li>Implements lightweight libc library interfaces, the interface name contains <code class="highlighter-rouge">tb_xxx</code> prefix for avoiding conflict</li>
  <li>Implements strixxx strrxxx wcsixxx wcsrxxx interface extension</li>
  <li>Optimizes some frequently-used interface, .e.g. memset, memcpy, strcpy …</li>
  <li>Implements <code class="highlighter-rouge">memset_u16</code>, <code class="highlighter-rouge">memset_u32</code>, <code class="highlighter-rouge">memset_u64</code> extension interfaces</li>
</ul>

<h4 id="the-libm-library">The libm library</h4>

<ul>
  <li>Implements lightweight libm library interfaces, the interface name contains <code class="highlighter-rouge">tb_xxx</code> prefix for avoiding conflict</li>
  <li>Supports float and double type</li>
</ul>

<h4 id="the-regex-library">The regex library</h4>

<ul>
  <li>Supports match and replace</li>
  <li>Supports global/multiline/caseless mode</li>
  <li>Uses pcre, pcre2 and posix regex modules</li>
</ul>

<h4 id="the-hash-library">The hash library</h4>

<ul>
  <li>Implements crc32, adler32, md5 and sha1 hash algorithm</li>
  <li>Implements some string hash algorithms (.e.g bkdr, fnv32, fnv64, sdbm, djb2, rshash, aphash …)</li>
  <li>Implements uuid generator</li>
</ul>

<h4 id="the-asynchronous-io-library-deprecated">The asynchronous io library (deprecated)</h4>

<ul>
  <li>Please uses coroutine to implement asio programming</li>
</ul>

<h2 id="todolist">Todolist</h2>

<ul>
  <li>Add server module</li>
  <li>Reconstruction xml module</li>
  <li>Add more algorithms and container</li>
  <li>Optimizes more libc interfaces</li>
  <li>Implements more libm interfaces and not wrap it only</li>
</ul>

<h2 id="projects">Projects</h2>

<p>Some projects using tbox:</p>

<ul>
  <li><a href="https://github.com/waruqi/gbox">gbox</a></li>
  <li><a href="https://github.com/waruqi/vm86">vm86</a></li>
  <li><a href="http://www.xmake.io">xmake</a></li>
  <li><a href="https://github.com/waruqi/itrace">itrace</a></li>
  <li><a href="https://github.com/waruqi/tbox/wiki/tbox-projects">more</a></li>
</ul>

<h2 id="build">Build</h2>

<p>Please install xmake first: <a href="https://github.com/waruqi/xmake">xmake</a></p>

<div class="highlighter-rouge"><pre class="highlight"><code># build for the host platform
cd ./tbox
xmake

# build for the mingw platform
cd ./tbox
xmake f -p mingw --sdk=/home/mingwsdk 
xmake

# build for the iphoneos platform
cd ./tbox
xmake f -p iphoneos 
xmake

# build for the android platform
cd ./tbox
xmake f -p android --ndk=xxxxx
xmake

# build for the linux cross-platform
cd ./tbox
xmake f -p linux --sdk=/home/sdk # --toolchains=/home/sdk/bin
xmake
</code></pre>
</div>

<h2 id="example">Example</h2>

<div class="highlighter-rouge"><pre class="highlight"><code>#include "tbox/tbox.h"

int main(int argc, char** argv)
{
    // init tbox
    if (!tb_init(tb_null, tb_null)) return 0;

    // trace
    tb_trace_i("hello tbox");

    // init vector
    tb_vector_ref_t vector = tb_vector_init(0, tb_element_cstr(tb_true));
    if (vector)
    {
        // insert item
        tb_vector_insert_tail(vector, "hello");
        tb_vector_insert_tail(vector, "tbox");

        // dump all items
        tb_for_all (tb_char_t const*, cstr, vector)
        {
            // trace
            tb_trace_i("%s", cstr);
        }

        // exit vector
        tb_vector_exit(vector);
    }

    // init stream
    tb_stream_ref_t stream = tb_stream_init_from_url("http://www.xxx.com/file.txt");
    if (stream)
    {
        // open stream
        if (tb_stream_open(stream))
        {
            // read line
            tb_long_t size = 0;
            tb_char_t line[TB_STREAM_BLOCK_MAXN];
            while ((size = tb_stream_bread_line(stream, line, sizeof(line))) &gt;= 0)
            {
                // trace
                tb_trace_i("line: %s", line);
            }
        }

        // exit stream
        tb_stream_exit(stream);
    }

    // wait some time
    getchar();

    // exit tbox
    tb_exit();
    return 0;
}
</code></pre>
</div>

<h4 id="contacts">Contacts</h4>

<ul>
  <li>Email：<a href="mailto:waruqi@gmail.com">waruqi@gmail.com</a></li>
  <li>Homepage：<a href="http://www.tboox.org/cn">TBOOX Open Source Project</a></li>
  <li>Community：<a href="http://www.tboox.org/forum">TBOOX Open Source Community</a></li>
</ul>



      <footer class="site-footer">
  <span class="site-footer-owner">Copyright (c) 2015-2017 <a href="http://www.tboox.org">tboox.org</a>.</span>
  <span class="site-footer-power">
    <span>
        <!--Site powered by <a href="https://jekyllrb.com/">Jekyll</a> & <a href="http://pages.coding.me">Coding Pages</a>.-->
        Site powered by <a href="https://jekyllrb.com/">Jekyll</a> & <a href="https://pages.github.com/">Github Pages</a>.
    </span>
    <span>
        Theme designed by <a href="https://github.com/pietromenna/jekyll-cayman-theme">cayman</a>.
    </span>
</span>
</footer>


    </section>

  </body>
</html>
